/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package atrevaluator;

import java.util.ArrayList;

/**
 *
 * @author iknoth
 */
public class TermItem {

    private ArrayList<String> variants;
    private Double confidence; 
    private String stem;

    public String getStem() {
        return stem;
    }

    public Double getConfidence() {
        return confidence;
    }

    public ArrayList<String> getVariants() {
        return variants;
    }

    public TermItem(ArrayList<String> variants, Double confidence) {
        this.variants = variants;
        this.confidence = confidence;
        this.stem = this.variants.get(0).toLowerCase();
    }
    
    @Override
    public boolean equals(Object obj) {
        
        if (obj.getClass() == String.class) {
                        
           String objString = (String) obj;
           
           return (objString.equalsIgnoreCase(this.stem));           
           
        } else {
            return false;
        }        
    }

    /** Returns true iff this term is a fragment of the term in object*/
    public boolean fragmentEquals(Object obj) {
         if (obj.getClass() == String.class) {
                        
           String objString = (String) obj;           
           String[] wordsObj = objString.split(" ");
           String[] wordsThis = this.stem.split(" ");
           boolean found = false;
           int i = 0;
           int j = 0;
           
           while (!found && (i < wordsThis.length)) {
               if (wordsObj[j].equalsIgnoreCase(wordsThis[i])) {                    
                    j ++;
               }
               
               i ++;
               found = (j == wordsObj.length);
           }
           
           return found;           
           
           //return (objString.toLowerCase().contains(this.stem)); // || (this.stem.contains(objString.toLowerCase())));
           
        } else {
            return false;
        }        
    }
    
    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + (this.variants != null ? this.stem.hashCode() : 0);        
        return hash;
    }
    
}
